home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Array2.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  1004 b   |  31 lines  |  [TEXT/R*ch]

  1. (* Array2 -- as of 1995-09-12 *)
  2.  
  3. (* Representation of an m * n array: an m-vector of n-arrays (rows), 
  4.    and the dimensions (m, n) *)
  5.  
  6. type 'a array2 = 'a Array.array Vector.vector * int * int
  7.  
  8. val maxLen = Array.maxLen;
  9.  
  10. fun array (m, n, x) = 
  11.     (Vector.tabulate(m, fn _ => Array.array(n, x)), m, n);
  12.  
  13. fun tabulate (m, n, f) = 
  14.     (Vector.tabulate(m, fn i => Array.tabulate(n, fn j => f(i,j))), m, n); 
  15.  
  16. fun dim (a,m,n) = (m,n);
  17.  
  18. fun sub((a,m,n), i, j) = Array.sub(Vector.sub(a, i), j);
  19.  
  20. fun update((a,m,n), i, j, x) = Array.update(Vector.sub(a, i), j, x);
  21.  
  22. fun extract1((a,m,n), i, j, lenopt) = 
  23.     Array.extract(Vector.sub(a, i), j, lenopt);
  24.  
  25. fun extract2((a,m,n), i, j, NONE) =
  26.     if i<0 orelse j<0 orelse i>m orelse j>=n then raise Subscript
  27.     else Vector.tabulate(m-i, fn k => Array.sub(Vector.sub(a, i+k), j))
  28.   | extract2((a,m,n), i, j, SOME len) =
  29.     if i<0 orelse j<0 orelse i>m orelse j>=n then raise Subscript
  30.     else Vector.tabulate(len, fn k => Array.sub(Vector.sub(a, i+k), j))
  31.